﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Bases.CityView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:be="clr-namespace:Corina.Interactivity.Silverlight;assembly=Corina.Interactivity.Silverlight"
                     xmlns:controls="clr-namespace:Corina.Controls.Silverlight;assembly=Corina.Controls.Silverlight"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                     xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                     Title="城市"
                     d:DesignHeight="480"
                     d:DesignWidth="640"
                     mc:Ignorable="d">
    <navigation:PageView.DataContext>
        <localViewmodel:CityViewmodel />
    </navigation:PageView.DataContext>
    <Grid x:Name="LayoutRoot">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <sdk:AutoCompleteBox FilterMode="Contains"
                                     IsDropDownOpen="True"
                                     IsTextCompletionEnabled="True"
                                     ItemsSource="{Binding ProvinceCollection}"
                                     MinimumPrefixLength="0"
                                     SelectedItem="{Binding SelectedProvince,
                                                            Mode=TwoWay}"
                                     ValueMemberPath="Name"
                                     be:AutoCompleteBoxHelper.OtherPaths="English,Name">
                    <sdk:AutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock>
                                <Run Text="{Binding Name}" />
                                <Run Text="（" />
                                <Run Text="{Binding English}" />
                                <Run Text="）" />
                            </TextBlock>
                        </DataTemplate>
                    </sdk:AutoCompleteBox.ItemTemplate>
                    <i:Interaction.Triggers>
                        <be:AutoCompleteBoxTrigger>
                            <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                        </be:AutoCompleteBoxTrigger>
                    </i:Interaction.Triggers>
                </sdk:AutoCompleteBox>

                <TextBlock Grid.Column="1"
                           Margin="12,0,0,0"
                           VerticalAlignment="Center"
                           Style="{StaticResource ControlLabelStyle}"
                           Text="关键字：" />
                <TextBox Grid.Column="2" Text="{Binding Keywords, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    <i:Interaction.Triggers>
                        <be:TextBoxEnterKeyTrigger>
                            <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                        </be:TextBoxEnterKeyTrigger>
                    </i:Interaction.Triggers>
                </TextBox>

                <Button Grid.Column="4"
                        Width="60"
                        Command="{Binding InsertCommand}"
                        Content="新增" />
            </Grid>

            <toolkit:BusyIndicator Grid.Row="1"
                                   BusyContent="{StaticResource IDS_BUSYCONTENT_LOADING}"
                                   IsBusy="{Binding IsBusy}">
                <sdk:DataGrid Margin="0,12,0,0"
                              AutoGenerateColumns="False"
                              ColumnWidth="*"
                              ItemsSource="{Binding CitiesCollection}">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn Binding="{Binding Code}" Header="编号" />
                        <sdk:DataGridTextColumn Binding="{Binding Name}" Header="名称" />
                        <sdk:DataGridTextColumn Binding="{Binding English}" Header="英文名" />
                        <sdk:DataGridTextColumn Binding="{Binding PostCode}" Header="邮编" />
                        <sdk:DataGridTextColumn Binding="{Binding AreaCode}" Header="区号" />
                        <sdk:DataGridTemplateColumn MinWidth="100" Header="操作">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel VerticalAlignment="Center" Orientation="Horizontal">
                                        <HyperlinkButton Content="编辑">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                        <HyperlinkButton Margin="12,0" Content="删除">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                    </StackPanel>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </toolkit:BusyIndicator>

            <StackPanel Grid.Row="2"
                        HorizontalAlignment="Right"
                        Orientation="Horizontal">
                <Button Command="{Binding FirstPageCommand}" Style="{StaticResource FirstPageButtonStyle}" />
                <Button Margin="12,0"
                        Command="{Binding PreviousPageCommand}"
                        Style="{StaticResource PreviousPageButtonStyle}" />
                <TextBlock Margin="12,0" VerticalAlignment="Center">
                    <Run Text="{Binding Index}" />
                    <Run Text="/" />
                    <Run Text="{Binding PagesCount}" />
                </TextBlock>
                <Button Margin="12,0"
                        Command="{Binding NextPageCommand}"
                        Style="{StaticResource NextPageButtonStyle}" />
                <Button Command="{Binding LastPageCommand}" Style="{StaticResource LastPageButtonStyle}" />
            </StackPanel>
        </Grid>


        <controls:PromptDialog Title="{Binding Operation,
                                               ConverterParameter=ENTITYOPERATION,
                                               Converter={StaticResource EnumTranslationConverter}}"
                               VerticalContentAlignment="Stretch"
                               CloseCommand="{Binding CancelCommand}"
                               Padding="50"
                               Visibility="{Binding ShowUpdate,
                                                    Converter={StaticResource BooleanToVisibilityConverter}}"
                               WindowHeight="400"
                               WindowWidth="400">
            <Grid Margin="12" HorizontalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <ScrollViewer BorderThickness="0">
                    <StackPanel Width="300">
                        <TextBlock Text="所在省份" />
                        <ComboBox ItemsSource="{Binding ProvinceCollection}" SelectedItem="{Binding SelectedUpdateProvince, Mode=TwoWay}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Name}" />
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                        <TextBlock Margin="0,12,0,0" Text="编号" />
                        <TextBox IsReadOnly="True" Text="{Binding UpdateEntity.Code}" />
                        <TextBlock Margin="0,12,0,0" Text="名称" />
                        <TextBox Text="{Binding UpdateEntity.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        <TextBlock Margin="0,12,0,0" Text="英文名" />
                        <TextBox Text="{Binding UpdateEntity.English, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        <TextBlock Margin="0,12,0,0" Text="邮编" />
                        <TextBox Text="{Binding UpdateEntity.PostCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        <TextBlock Margin="0,12,0,0" Text="区号" />
                        <TextBox Text="{Binding UpdateEntity.AreaCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>
                </ScrollViewer>

                <StackPanel Grid.Row="1"
                            Margin="0,12,0,0"
                            HorizontalAlignment="Right"
                            Orientation="Horizontal">
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding SubmitCommand}"
                            Content="提交" />
                    <Button Width="60"
                            Command="{Binding CancelCommand}"
                            Content="取消" />
                </StackPanel>
            </Grid>
        </controls:PromptDialog>

    </Grid>
</navigation:PageView>
